package com.blog.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.Calendar;
import java.util.Set;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllUsers", query = "select myUser from User myUser"),
		@NamedQuery(name = "findUserById", query = "select myUser from User myUser where myUser.id = ?1"),
		@NamedQuery(name = "findUserByImage", query = "select myUser from User myUser where myUser.image = ?1"),
		@NamedQuery(name = "findUserByImageContaining", query = "select myUser from User myUser where myUser.image like ?1"),
		@NamedQuery(name = "findUserByNickName", query = "select myUser from User myUser where myUser.nickName = ?1"),
		@NamedQuery(name = "findUserByNickNameContaining", query = "select myUser from User myUser where myUser.nickName like ?1"),
		@NamedQuery(name = "findUserByPassword", query = "select myUser from User myUser where myUser.password = ?1"),
		@NamedQuery(name = "findUserByPasswordContaining", query = "select myUser from User myUser where myUser.password like ?1"),
		@NamedQuery(name = "findUserByPrimaryKey", query = "select myUser from User myUser where myUser.id = ?1"),
		@NamedQuery(name = "findUserByRegister", query = "select myUser from User myUser where myUser.register = ?1"),
		@NamedQuery(name = "findUserBySex", query = "select myUser from User myUser where myUser.sex = ?1"),
		@NamedQuery(name = "findUserBySexContaining", query = "select myUser from User myUser where myUser.sex like ?1"),
		@NamedQuery(name = "findUserByUsername", query = "select myUser from User myUser where myUser.username = ?1"),
		@NamedQuery(name = "findUserByUsernameContaining", query = "select myUser from User myUser where myUser.username like ?1") })
@Table(catalog = "blog", name = "user")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "blog/com/blog/domain", name = "User")
@XmlRootElement(namespace = "blog/com/blog/domain")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "username", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String username;
	/**
	 */

	@Column(name = "password", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String password;
	/**
	 */

	@Column(name = "nickName", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String nickName;
	/**
	 */

	@Column(name = "sex", length = 2)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String sex;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "register")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar register;
	/**
	 */

	@Column(name = "image", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String image;

	/**
	 */
	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	transient java.util.Set<com.blog.domain.Blog> blogs;
	/**
	 */
	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	transient java.util.Set<com.blog.domain.Type> types;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 */
	public String getUsername() {
		return this.username;
	}

	/**
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 */
	public String getPassword() {
		return this.password;
	}

	/**
	 */
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	/**
	 */
	public String getNickName() {
		return this.nickName;
	}

	/**
	 */
	public void setSex(String sex) {
		this.sex = sex;
	}

	/**
	 */
	public String getSex() {
		return this.sex;
	}

	/**
	 */
	public void setRegister(Calendar register) {
		this.register = register;
	}

	/**
	 */
	public Calendar getRegister() {
		return this.register;
	}

	/**
	 */
	public void setImage(String image) {
		this.image = image;
	}

	/**
	 */
	public String getImage() {
		return this.image;
	}

	/**
	 */
	public void setBlogs(Set<Blog> blogs) {
		this.blogs = blogs;
	}

	/**
	 */
	public Set<Blog> getBlogs() {
		if (blogs == null) {
			blogs = new java.util.LinkedHashSet<com.blog.domain.Blog>();
		}
		return blogs;
	}

	/**
	 */
	public void setTypes(Set<Type> types) {
		this.types = types;
	}

	/**
	 */
	public Set<Type> getTypes() {
		if (types == null) {
			types = new java.util.LinkedHashSet<com.blog.domain.Type>();
		}
		return types;
	}

	/**
	 */
	public User() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(User that) {
		setId(that.getId());
		setUsername(that.getUsername());
		setPassword(that.getPassword());
		setNickName(that.getNickName());
		setSex(that.getSex());
		setRegister(that.getRegister());
		setImage(that.getImage());
		setBlogs(new java.util.LinkedHashSet<com.blog.domain.Blog>(that.getBlogs()));
		setTypes(new java.util.LinkedHashSet<com.blog.domain.Type>(that.getTypes()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("username=[").append(username).append("] ");
		buffer.append("password=[").append(password).append("] ");
		buffer.append("nickName=[").append(nickName).append("] ");
		buffer.append("sex=[").append(sex).append("] ");
		buffer.append("register=[").append(register).append("] ");
		buffer.append("image=[").append(image).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof User))
			return false;
		User equalCheck = (User) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
